package org.anti996.bankms.model;

import org.anti996.bankms.dao.UserDao;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TRecord {
    private int idFrom;
    private int idTo;
    private String currency;
    private double amount;
    private Timestamp timestp;

    public static String describe(Card card, TRecord TRecord) {
        String line;
        if (card.getId() == TRecord.idFrom) {
            line = String.format("转出：%.2f，时间：%s", TRecord.amount, TRecord.timestp);
        } else {
            line = String.format("转入：%.2f，时间：%s", TRecord.idFrom == 0 ? TRecord.amount : TRecord.amount * UserDao.CURRENCY_RATES.get(TRecord.currency) / UserDao.CURRENCY_RATES.get(card.getCurrency()), TRecord.timestp);
        }
        return line;
    }
}
